package bg.code.commons.builder.templte;

import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.loader.ResourceLoader;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

/**
 * @author 郑兴泉 956607644@qq.com
 * @data 2020/3/18
 * 描述：
 */
public class VelocityTemplateResourceLoader extends ResourceLoader {

    List<String> VM_GLOBALS = Arrays.asList(new String[]{"VM_global_library.vm"});

    @Override
    public void init(ExtendedProperties extendedProperties) {
    }

    @Override
    public InputStream getResourceStream(String s)
            throws ResourceNotFoundException {
        if (this.VM_GLOBALS.contains(s)) {
            return null;
        }
        return new ByteArrayInputStream(s.getBytes());
    }

    @Override
    public boolean isSourceModified(Resource resource) {
        return false;
    }

    @Override
    public long getLastModified(Resource resource) {
        return 0L;
    }
}
